<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Chatbox_model extends CI_Model {
    
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

	function _showchatbox($num,$offset){
		$this->load->database();   
		$this->db->order_by("id", "desc");
		$query = $this->db->get('chatbox',$num,$offset);
		if($query->num_rows() > 0){
			 return $query->result();
		}else{
			return null;
		}
	}

	function _totalchatbox(){
		$this->load->database();
		return $this->db->count_all('chatbox');
	}
	
	function _addchat($username,$userid,$message){
    	$this->load->database();
    	$data = array( 
            'username'=>$username,
            'userid'=>$userid,
    		'message'=>$message,
    		'created_at'=>date("Y-m-d h:s:m")
            );
    	$this->db->insert('chatbox', $data); 
    }
	
}
    ?>